
/*
 * @Descripttion: 
 * @Author: ziwei
 * @Date: 2022-07-03 11:55:13
 * @LastEditors: ziwei
 * @LastEditTime: 2022-07-03 15:12:13
 */
let married:boolean = true;
let age:number = 10;
let first_name:string = 'zf'
let arr1:number[]=[1,2,3]
let arr2:Array<number> = [4,5,6]
//元组类型tuple 数量和类型已知的数组:类型和数量是固定的
let zhufeng:[string,number] = ['zhufeng',10]
//泛型 类型推倒 类型声明 类型编程
//枚举类型
enum Gender{
    GIRL,
    BOY
}
console.log(Gender.BOY,Gender[1]);
console.log(Gender.GIRL,Gender[0]);

//常量枚举
const enum Colors{
    RED,YELLOW,BLUE
}
let myColor = [Colors.RED,Colors.YELLOW,Colors.BLUE]
//任意类型
//any 数据结构太复杂
//如果变量定义为any类型，就跟JS差不多，不进行类型检查
//let root:any = document.getElementById('root')
//root.style.color = 'red'

// let element:HTMLElement|null = document.getElementById('root')
// element!.style.color = 'green';

//null undefined 是其它类型的字类型
//如果说stricNullChecks的只为true,则不能吧null undefined赋值给x
let x:number
x=1
// x=undefined
// x=null

let y:number|null|undefined
y=1
y=undefined
y=null

//never 代表不会出现的值 永远不
//1. 作为不会返回的函数的返回
function error(message:string):never {
    throw new Error('报错了')
    console.log('ok')
}

function loop():never{
    while(true){

    }
    console.log('ok')
}

function fn(x:number|string){
    if(typeof x === 'number'){
        console.log(x);
    }else if(typeof x === 'string'){
        console.log(x);
    }else{
        console.log(x);
    }
}

//void:没有返回值,没有任何类型 never
//函数没有返回值，那么就是void类型
//strictNull = false
function greeting():void{
    return undefined;
}
//void 和never的区别
//void可以被赋值给null undefined never不能包含任何类型
//返回类型void函数还能执行 但是返回never的函数无法正常执行
//Symbol
const s1 = Symbol('key')
const s2 = Symbol('key')
//console.log(s1==s2)
// esnext:最新版本JS

//BigInt  n 代表大整形
const max = BigInt(Number.MAX_SAFE_INTEGER);//2**53-1
console.log(max+1n===max+2n);

//JS类型Number BigInt  ts里的类型number biginit
//number和biginit 不兼容
let foo:number;
let bar:BigInt;
//foo = bar

//类型推倒
//包装对象 原始类型 对象类型
//原始类型 bool number null undefined 
let uname
uname=1
uname='zhufeng'
uname = null
let uname2 = 'zhufeng'

//包装对象 wrapper object
//原始类型 对象类型
//原始类型：numm bool string
let name2 = 'zhufeng'
//如果内部自动帮你包装成对象类型
console.log(name2.toUpperCase());
console.log(new String(name2).toUpperCase());

let isOk1:boolean = true
let isOk2:boolean = Boolean(1)
// let isOk3:boolean = new Boolean(1)

//联合类型
let name3:string | number
console.log(name3!.toString());
name3 = 3;
console.log(name3.toFixed(2));
name3 = 'zhufeng'
console.log(name3!.length);

//类型断言 联合类型的变量指定为更加具体的变量
let name4:string|number;
console.log((name4! as number).toFixed(2));
console.log((name4! as String).length);
//- 双重断言
console.log(name4! as any as boolean);

//- 字面量类型 和类型字面量
const up:'Up' = 'Up'
const down:'Down' = 'Down'
type Direction = 'Up'|'Down'|'Left'|'right'
//可以实现枚举的效果
function move(direction:Direction){
}
move('Down')

//类型字面量
type Person = {
    name:string,
    age:number
}
let p1 = {
    name:'age',
    age:10
}
//字符串字面量和联合类型
type T1 = '1'|'2'|'3';
type T2 = string|number|boolean;

